/*
 * @(#)SetWeigthDialog.java	Robert Denda
 */

/** 
 *
 * @author 	Robert Denda
 * @version     1.0, 20.06.97
 */

import java.awt.*;

public class SetWeightDialogue extends Frame {
  TextMethods text;
  int value;
  TextField textField;
  debug DEBUG = new debug();
  boolean done = false;
  Panel textPanel;
  Panel okayPanel;

  SetWeightDialogue( int id, int oldValue, TextMethods text ) {
    this.text = text;
    this.value = oldValue;
    setTitle( text.setWeightDialogueTitleText + " " + text.linkTitleText + " " + id );
    add( "North", new Label( text.setWeightDialogueText + " " + text.linkTitleText + id ) );
    textField = new TextField( 10 );
    textField.setText( "" + oldValue );
    textPanel = new Panel();
    textPanel.add( textField );
    add( "Center", textPanel );
    okayPanel = new Panel();
    okayPanel.add( new Button( text.okayButtonText ) );
    okayPanel.add( new Button( text.cancelButtonText ) );
    add( "South", okayPanel );
    pack();
  } // SetWeightDialogue.SetWeightDialogue

  synchronized public int result() {
    while ( !done ) {
      try {
	wait();
      } catch( InterruptedException e ) {
	DEBUG.out( "interrupted in result()", this );
      } // try
    } // if 
    return value;
  } // SetWeightDialogue.result

  synchronized public boolean action( Event e, Object obj ) {
    if ( ( (String) obj ).equals( text.okayButtonText ) ) {
      value = Integer.valueOf( textField.getText() ).intValue();
    } // if
    notifyAll();
    dispose();
    done = true;
    return true;
  } // SetWeightDialogue.action
} // SetWeightDialogue
